<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>登录 - 夜读书</title>
    <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="format-detection" content="telephone=no">
    <meta name="author" content="夜读书">
    <meta name="description" content="夜读书的登录。">
    <meta name="keywords" content="夜读书">
    <link rel="stylesheet" href="{{ asset('/bootstrap-3.3.5-dist/css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/mobile.css') }}">    
    <script src="{{ asset('/scripts/jquery/jquery-1.11.3.min.js') }}"></script>
    <script src="{{ asset('/bootstrap-3.3.5-dist/js/bootstrap.min.js') }}"></script>
</head>
<body>
@include('mobile.navlogin')
<div id="login">

    <div class="weltitle">欢迎来到夜读书</div>
    <div class="uinn-at1">
        <form id="ylogin" name="ylogin" action="" method="post">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <div class="item">
                <div class="sek">
                    <input id="username" name="username" placeholder="手机号 / 邮箱" type="text" class="textline">
                </div>
                <div class="sek">
                    <input id="password" name="password" placeholder="密码" type="password" class="textline">
                </div>
                <div class="u-tips u-tips-err">
                    <span></span>
                </div>
                <div class="ub ub-ver">
                    <div class="uinn-at1">
                        <button type="submit" class="btn btn-success" style="width:100%;">登录</button>
                    </div>
                    <div class="reglogin">
                        <span class="register"><a href="{{url('mobile/usreg')}}">立即注册</a></span>
                        <span class="register">|</span>
                        <span class="resetpassword">忘记密码 </span>
                    </div>
                </div>
            </div>
        </form>
    </div>
        
</div> 

@include('mobile.footer')
</body>
<script>
// 提交验证，异步传输 
$(document).ready(function(){
    $("form").submit(function (){
        if ($("#username").val() == '' || $("#password").val() == ''){
            //alert("帐号和密码不能为空!");
            $(".u-tips-err").html("<span><font color='red'>帐号和密码不能为空!</font></span>");
            return false;
        }
        else{
            $.ajax({
                type: 'post',   // 路由器中提交页面使用post方式，这里也需要用post
                url: 'login',       //处理登录页面,注意返回内容，成功返回OK
                dataType: 'text',
                data: $("form").serialize(),
                success: function (msg) {
                    if (msg == "ok"){
                        //window.location.href = "books"; //登录成功，跳转到books页面
                        //window.history.back(); //登录成功，跳转到前一页,不刷新
                        //window.history.go(-1); //登录成功，跳转到前一页,不刷新
                        location.href=document.referrer; //document.referrer是获取上一页的url
                    }else{                          
                        //alert("帐号或密码不正确，请您重新输入!"); 
                        $(".u-tips-err").html("<span><font color='red'>帐号或密码不正确，请您重新输入!</font></span>");
                        return false;                      
                    }
                }
            });
        }
    return false; // 要阻止表单提交     
    });
});
</script>
</html>
